#include "Pursue.h"
#include "Agent.h"
#include "SteeringOutput.h"

namespace Engine
{
	Pursue::Pursue():prediction(0.0f), m_actualTarget(nullptr) {m_target = new Agent;}

	void Pursue::SetMaxPrediction(float m)
	{
		m_maxPrediction = m;
	}

	void Pursue::SetTarget(Agent* t)
	{
		m_actualTarget = t;
	}

	void Pursue::Update(SteeringOutput* output)
	{
		Vec3 direction = m_actualTarget->GetPos() - m_parent ->GetPos();

		float distance = direction.Length();

		if(m_parent->GetSpeedSquared() <= distance / m_maxPrediction)
		{
			prediction = m_maxPrediction;
		}
		else
		{
			prediction = distance / m_parent->GetSpeedSquared();
		}

		Vec3 temp_pos = m_actualTarget->PredictFuturePosition(prediction);

		Seek::m_target ->SetPos(temp_pos);

		Seek::Update(output);
	}
}